<?php
require_once("database.php");
class xl_hoa_don extends database
{
	function danh_sach($vi_tri, $so_luong)
	{
		$vi_tri = intval($vi_tri);
		$so_luong = intval($so_luong);
		$sql = "select * from hoa_don limit $vi_tri, $so_luong";
		$this->setQuery($sql);
		return $this->loadAllRow();
	}
	function so_luong()
	{
		$sql = "select count(*) from hoa_don";
		$this->setQuery($sql);
		return $this->loadResult();
	}
	function so_luong_theo_ngay($ngay)
	{
		$from = date("$ngay 0:0:0");
		$to = date("$ngay 23:59:59");
		$sql = "select count(*) from hoa_don where '$from' <= ngay_tao and ngay_tao <= '$to'";
		$this->setQuery($sql);
		return $this->loadResult();
	}
	function xem($ma)
	{
		$ma = intval($ma);

		$sql = "select * from hoa_don where ma = '$ma'";
		$this->setQuery($sql);
		return $this->loadRow();
	}
	
	function xem_code($code)
	{
		$code = stripslashes($code);
		$code = addslashes($code);
		$sql = "select * from hoa_don where code = '$code'";
		$this->setQuery($sql);
		return $this->loadRow();
	}
	
	function xoa($ma)
	{
		$ma = intval($ma);

		$sql = "delete from hoa_don where ma = '$ma'";
		$this->setQuery($sql);
		return $this->query();
	}
	function them($code,$ho_ten, $gioi_tinh, $ngay_sinh, $dia_chi, $email, $dien_thoai, $ngay_tao, $trang_thai, $ghi_chu, $tong_tien, $ho_ten_nguoi_nhan, $dia_chi_nguoi_nhan, $dien_thoai_nguoi_nhan, $ma_cuoc_phi_van_chuyen, $ma_phuong_thuc_thanh_toan)
	{
		$code = stripslashes($code);
		$code = addslashes($code);
		$ho_ten = stripslashes($ho_ten);
		$ho_ten = addslashes($ho_ten);
		$dia_chi = stripslashes($dia_chi);
		$dia_chi = addslashes($dia_chi);
		$email = stripslashes($email);
		$email = addslashes($email);
		$dien_thoai = stripslashes($dien_thoai);
		$dien_thoai = addslashes($dien_thoai);
		$ghi_chu = stripslashes($ghi_chu);
		$ghi_chu = addslashes($ghi_chu);
		$tong_tien = intval($tong_tien);
		$ho_ten_nguoi_nhan = stripslashes($ho_ten_nguoi_nhan);
		$ho_ten_nguoi_nhan = addslashes($ho_ten_nguoi_nhan);
		$dia_chi_nguoi_nhan = stripslashes($dia_chi_nguoi_nhan);
		$dia_chi_nguoi_nhan = addslashes($dia_chi_nguoi_nhan);
		$dien_thoai_nguoi_nhan = stripslashes($dien_thoai_nguoi_nhan);
		$dien_thoai_nguoi_nhan = addslashes($dien_thoai_nguoi_nhan);
		$ma_cuoc_phi_van_chuyen = stripslashes($ma_cuoc_phi_van_chuyen);
		$ma_cuoc_phi_van_chuyen = addslashes($ma_cuoc_phi_van_chuyen);
		$ma_phuong_thuc_thanh_toan = stripslashes($ma_phuong_thuc_thanh_toan);
		$ma_phuong_thuc_thanh_toan = addslashes($ma_phuong_thuc_thanh_toan);

		$sql = "INSERT INTO hoa_don(code,ho_ten,gioi_tinh,ngay_sinh,dia_chi,email,dien_thoai,ngay_tao,trang_thai,ghi_chu,tong_tien,ho_ten_nguoi_nhan,dia_chi_nguoi_nhan,dien_thoai_nguoi_nhan,ma_cuoc_phi_van_chuyen,ma_phuong_thuc_thanh_toan) VALUES ('$code','$ho_ten','$gioi_tinh','$ngay_sinh','$dia_chi','$email','$dien_thoai','$ngay_tao','$trang_thai','$ghi_chu','$tong_tien','$ho_ten_nguoi_nhan','$dia_chi_nguoi_nhan','$dien_thoai_nguoi_nhan','$ma_cuoc_phi_van_chuyen','$ma_phuong_thuc_thanh_toan')";
		$this->setQuery($sql);
		return $this->query();
	}
	function cap_nhat($ma,$code,$ho_ten, $gioi_tinh, $ngay_sinh, $dia_chi, $email, $dien_thoai, $ngay_tao, $trang_thai, $ghi_chu, $tong_tien, $ho_ten_nguoi_nhan, $dia_chi_nguoi_nhan, $dien_thoai_nguoi_nhan, $ma_cuoc_phi_van_chuyen, $ma_phuong_thuc_thanh_toan)
	{
		$ma = intval($ma);
		$code = stripslashes($code);
		$code = addslashes($code);
		$ho_ten = stripslashes($ho_ten);
		$ho_ten = addslashes($ho_ten);
		$dia_chi = stripslashes($dia_chi);
		$dia_chi = addslashes($dia_chi);
		$email = stripslashes($email);
		$email = addslashes($email);
		$dien_thoai = stripslashes($dien_thoai);
		$dien_thoai = addslashes($dien_thoai);
		$ghi_chu = stripslashes($ghi_chu);
		$ghi_chu = addslashes($ghi_chu);
		$tong_tien = intval($tong_tien);
		$ho_ten_nguoi_nhan = stripslashes($ho_ten_nguoi_nhan);
		$ho_ten_nguoi_nhan = addslashes($ho_ten_nguoi_nhan);
		$dia_chi_nguoi_nhan = stripslashes($dia_chi_nguoi_nhan);
		$dia_chi_nguoi_nhan = addslashes($dia_chi_nguoi_nhan);
		$dien_thoai_nguoi_nhan = stripslashes($dien_thoai_nguoi_nhan);
		$dien_thoai_nguoi_nhan = addslashes($dien_thoai_nguoi_nhan);
		$ma_cuoc_phi_van_chuyen = stripslashes($ma_cuoc_phi_van_chuyen);
		$ma_cuoc_phi_van_chuyen = addslashes($ma_cuoc_phi_van_chuyen);
		$ma_phuong_thuc_thanh_toan = stripslashes($ma_phuong_thuc_thanh_toan);
		$ma_phuong_thuc_thanh_toan = addslashes($ma_phuong_thuc_thanh_toan);

		$sql ="UPDATE hoa_don SET code= '$code', ho_ten= '$ho_ten', gioi_tinh= '$gioi_tinh', ngay_sinh= '$ngay_sinh', dia_chi= '$dia_chi', email= '$email', dien_thoai= '$dien_thoai', ngay_tao= '$ngay_tao', trang_thai= '$trang_thai', ghi_chu= '$ghi_chu', tong_tien= '$tong_tien', ho_ten_nguoi_nhan= '$ho_ten_nguoi_nhan', dia_chi_nguoi_nhan= '$dia_chi_nguoi_nhan', dien_thoai_nguoi_nhan= '$dien_thoai_nguoi_nhan', ma_cuoc_phi_van_chuyen= '$ma_cuoc_phi_van_chuyen', ma_phuong_thuc_thanh_toan= '$ma_phuong_thuc_thanh_toan' WHERE ma = '$ma'";
		$this->setQuery($sql);
		return $this->query();
	}
	
	function cap_nhat_tong_tien($ma, $tong_tien)
	{
		$ma = intval($ma);
		$tong_tien = intval($tong_tien);

		$sql ="UPDATE hoa_don SET tong_tien= '$tong_tien' WHERE ma = '$ma'";
		$this->setQuery($sql);
		return $this->query();
	}
	
	function tim_kiem ($tu_khoa)
	{
		$sql = "select * from hoa_don where	$ho_ten like %tu_khoa% or 	$dia_chi like %tu_khoa% or 	$email like %tu_khoa% or 	$dien_thoai like %tu_khoa% or 	$ghi_chu like %tu_khoa% or 	$ho_ten_nguoi_nhan like %tu_khoa% or 	$dia_chi_nguoi_nhan like %tu_khoa% or 	$dien_thoai_nguoi_nhan like %tu_khoa% or 	$ma_cuoc_phi_van_chuyen like %tu_khoa% or 	$ma_phuong_thuc_thanh_toan like %tu_khoa%"; 
		$this->setQuery($sql);
		return $this->loadAllRow();	
	}
 }
?>